package com.hz.springbootschedule.utils;


import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class SHA256Util {
    private static final String SHA_256 = "SHA-256";


    private SHA256Util() {
        try {
            MessageDigest.getInstance(SHA_256);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("SHA-256 not supported.");
        }
    }

    public static String makeHash(String password, String salt) {
        try {
            MessageDigest md = MessageDigest.getInstance(SHA_256);
            md.update(password.getBytes(StandardCharsets.UTF_8));
            byte[] byteData = md.digest(makeHash(salt.toLowerCase()));
            return Base64.getEncoder().encodeToString(byteData);
        } catch (Exception e) {
           e.printStackTrace();
        }
        return null;
    }

    private static byte[] makeHash(String val) throws NoSuchAlgorithmException {
        return MessageDigest.getInstance(SHA_256).digest(val.getBytes(StandardCharsets.UTF_8));
    }

    public static void main(String[] args) {
        //h8mlEvw6unnKj24r0+xuVUur+oKC0MFAAHMECEhaS+Q=
        //h8mlEvw6unnKj24r0+xuVUur+oKC0MFAAHMECEhaS+Q=
        //u3vjJTviS17REzQcdnWuS98L5HS3dybDG94wufdvyEw=
        //u3vjJTviS17REzQcdnWuS98L5HS3dybDG94wufdvyEw=
        //q6qtCVZh5Rt5JEoOfUtXGUmkWIvGW5P9vXooU8fZLTk=
       String pwd = SHA256Util.makeHash("111111","wzy");
        System.out.println(pwd);
    }
}
